package com.standard.logcat.sp

import android.content.Context
import android.content.SharedPreferences
import com.standard.logcat.provider.Init
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

class SP(
    private val sp: SharedPreferences =
        Init.context
            .getSharedPreferences("LogcatSharedPreferences", Context.MODE_PRIVATE)
) : SharedPreferences by sp

/**
 * 字符串存取
 */
class StringSP(private val key: String) : ReadWriteProperty<Any, String> {
    private val sp by lazy { SP() }

    override fun getValue(thisRef: Any, property: KProperty<*>): String {
        return sp.getString(key, "")!!
    }

    override fun setValue(thisRef: Any, property: KProperty<*>, value: String) {
        sp.edit().putString(key, value).commit()
    }
}